package com.wangsd.web.shop.service;

import com.gitee.fastmybatis.core.query.Query;
import com.wangsd.web.shop.entity.ActivityMember;
import com.wangsd.web.shop.mapper.ActivityMemberMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ActivityMemberService {
    @Resource
    private ActivityMemberMapper mapper;

    public void deleteByActivityId(Long activityId) {
        Query query = new Query();
        query.eq("activity_id", activityId);
        mapper.deleteByQuery(query);
    }

    public List<ActivityMember> selectByMiniOpenid(String miniOpenid, String receiveTime) {
        Query query = new Query();
        query.eq("mini_openid", miniOpenid);
        query.eq("receive_time", receiveTime);
        return mapper.list(query);
    }

    public void save(Long activityId, String miniOpenid, String receiveTime) {
        ActivityMember activityMember = new ActivityMember();
        activityMember.setActivityId(activityId);
        activityMember.setMiniOpenid(miniOpenid);
        activityMember.setReceiveTime(receiveTime);
        mapper.saveIgnoreNull(activityMember);
    }
}
